/*
 * FlagOT.java
 *
 * $Id: FlagOT.java,v 1.4 2009-04-27 06:21:59 juancarlos Exp $
 */
package org.ceteca.explica.core.common;

import java.io.Serializable;

import org.ceteca.explica.core.InterfaceExplica;
import org.ceteca.explica.core.installer.ResourceOT;

/**
 * Store class to hold the data of a flag.
 * <br/>
 * Responsibilities:
 * <li>
 * 	<ul> Store of flag data for exchanging data among presentation, 
 * business and data access layers. </ul>
 * </li>.
 * <br/>
 * @author Mario García García <mario@ceteca.es>
 * Copyright (c) 2009 Fundación Centro Tecnolóxico da Carne
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * <br/>
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * <br/>
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
public class FlagOT extends BaseVO implements Serializable{
	/**
	 * Internal id of the flag.
	 */
	private long idFlag;
	/**
	 * Name of the flag.
	 */
	private String name;
	
	private ResourceOT image;
	
	/**
	 * Version of the flag used by Hibernate for optimistic concurrency control.
	 */
	private Integer version = new Integer(0);
	private static final long serialVersionUID = 10000002;

	
	
	
	
	public FlagOT() {
		super();
		// TODO Auto-generated constructor stub
	}
	public ResourceOT getImage() {
		return image;
	}
	public void setImage(ResourceOT image) {
		this.image = image;
	}

	public long getIdFlag() {
		return idFlag;
	}
	public void setIdFlag(long idFlag) {
		this.idFlag = idFlag;
	}

	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	/**
	 * Gets the version of the flag used by Hibernate for optimistic concurrency control.
	 * @return Integer, version of the group.
	 */
	public Integer getVersion() {
		return version;
	}
	/**
	 * Sets up the version of the flag used by Hibernate for optimistic concurrency control.
	 * @param version Integer, version of the group.
	 */
	public void setVersion(Integer version) {
		this.version = version;
	}
	

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((image == null) ? 0 : image.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (getClass() != obj.getClass())
			return false;
		FlagOT other = (FlagOT) obj;
		if (image == null) {
			if (other.image != null)
				return false;
		} else if (!image.equals(other.image))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}
	/**
	 * Implementation of the toString() method to show the data of the FlagOT
	 * formatted.
	 */
	public String toString() {
		StringBuffer result = new StringBuffer();
		try {
			result.append("\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
			result.append("\nID: ");
			result.append(this.idFlag);
			result.append("\nNAME: ");
			result.append(this.name);
			result.append("\nIMAGE: ");
			result.append(this.image != null?this.image.getDescription():"NO IMAGE");
			
			result.append("\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
		}
		catch (Exception ex) {
			System.out.println("Error formatting FlagOT!");
			ex.printStackTrace();
			return null;
		}
		
		return result.toString();
	}
	
	@Override
	public boolean equals(Long id) {
		return id != null && this.idFlag == id.longValue();
	}
	
	@Override
	public long getInternalId() {
		return this.idFlag;
	}

	@Override
	public String getInternalValue() {
		return this.name;
	}
	
	@Override
	public String getEntityId() {
		return InterfaceExplica.EXPLICA_ENTITY_FLAG_ID;
	}

}
